package io.gitee.zhangbinhub.admin.workflow.conf

import com.mybatisflex.spring.FlexTransactionManager
import com.mybatisflex.spring.boot.MybatisFlexAutoConfiguration
import org.springframework.boot.autoconfigure.AutoConfigureAfter
import org.springframework.boot.autoconfigure.AutoConfigureBefore
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.transaction.PlatformTransactionManager
import org.springframework.transaction.annotation.TransactionManagementConfigurer

@AutoConfigureAfter(MybatisFlexAutoConfiguration::class)
@AutoConfigureBefore(value = [TransactionAutoConfiguration::class, DataSourceTransactionManagerAutoConfiguration::class])
@Configuration(proxyBeanMethods = false)
class MybatisFlexTransactionAutoConfiguration : TransactionManagementConfigurer {
    private val flexTransactionManager = FlexTransactionManager()

    @Bean(name = ["mybatisFlexTransactionManager"])
    override fun annotationDrivenTransactionManager(): PlatformTransactionManager = flexTransactionManager
}